<template>
  <div class="dashboard-editor-container">
    <github-corner class="github-corner"/>

    <panel-group @handleSetLineChartData="handleSetLineChartData"/>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chartData="lineChartData"/>
    </el-row>

<!--    <el-row :gutter="32">-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <raddar-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <pie-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--      <el-col :xs="24" :sm="24" :lg="8">-->
<!--        <div class="chart-wrapper">-->
<!--          <bar-chart/>-->
<!--        </div>-->
<!--      </el-col>-->
<!--    </el-row>-->

       <!-- <el-row :gutter="8">
         <el-col :xs="{span: 24}" :sm="{span: 24}" :md="{span: 24}" :lg="{span: 12}" :xl="{span: 12}" style="padding-right:8px;margin-bottom:30px;">
           <transaction-table />
         </el-col>
         <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
           <todo-list />
         </el-col>
         <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 12}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
           <box-card />
         </el-col>
       </el-row> -->
  </div>
</template>

<script>
  import GithubCorner from '@/components/GithubCorner'
  import PanelGroup from './components/PanelGroup'
  import LineChart from './components/LineChart'
  import RaddarChart from './components/RaddarChart'
  import PieChart from './components/PieChart'
  import BarChart from './components/BarChart'
  import TransactionTable from './components/TransactionTable'
  import TodoList from './components/TodoList'
  import BoxCard from './components/BoxCard'
  import {isWeek} from "../../utils";
  import {getEquipment} from "../../api/equipment";
  import {getEngineer} from "../../api/engineer";
  import {getProblem} from "../../api/problem";
  import {getEvaluate} from "../../api/evaluate";
  import {getRepair} from "../../api/repair";
  import {findWorkList} from "../../api/workOrder";

  const lineChartData = {
    engineer: {
      lastWeek: [100, 120, 161, 134, 105, 160, 165],
      thisWeek: [120, 82, 91, 154, 162, 140, 145]
    },
    suggestions: {
      lastWeek: [0, 0, 0, 0, 0, 0, 0],
      thisWeek: [0, 0, 0, 0, 0, 0, 0]
    },
    equipment: {
      lastWeek: [0, 0, 0, 0, 0, 0, 0],
      thisWeek: [0, 0, 0, 0, 0, 0, 0]
    },
    tutorialArticles: {
      lastWeek: [0, 0, 0, 0, 0, 0, 0],
      thisWeek: [0, 0, 0, 0, 0, 0, 0]
    } ,
    repair: {
      lastWeek: [0, 0, 0, 0, 0, 0, 0],
      thisWeek: [0, 0, 0, 0, 0, 0, 0]
    }
  }

  export default {
    name: 'Dashboard',
    components: {
      GithubCorner,
      PanelGroup,
      LineChart,
      RaddarChart,
      PieChart,
      BarChart,
      TransactionTable,
      TodoList,
      BoxCard
    },
    data() {
      return {
        lineChartData: lineChartData.repairmodify
      }
    },
    methods: {
      handleSetLineChartData(type) {
        this.lineChartData = lineChartData[type]
      },

      /**
       * 设置柱状图数据
       */
      setChartData(data,isThisWeek,Week){
        if (isThisWeek) {
          switch (Week) {
            case '星期一': {
              data.thisWeek[0] += 1
              break;
            }
            case '星期二': {
              data.thisWeek[1] += 1
              break;
            }
            case '星期三': {
              data.thisWeek[2] += 1
              break;
            }
            case '星期四': {
              data.thisWeek[3] += 1
              break;
            }
            case '星期五': {
              data.thisWeek[4] += 1
              break;
            }
            case '星期六': {
              data.thisWeek[5] += 1
              break;
            }
            case '星期日': {
              data.thisWeek[6] += 1
              break;
            }
            default:
              break
          }
        } else {
          switch (Week) {
            case '上周星期一': {
              data.lastWeek[0] += 1
              break;
            }
            case '上周星期二': {
              data.lastWeek[1] += 1
              break;
            }
            case '上周星期三': {
              data.lastWeek[2] += 1
              break;
            }
            case '上周星期四': {
              data.lastWeek[3] += 1
              break;
            }
            case '上周星期五': {
              data.lastWeek[4] += 1
              break;
            }
            case '上周星期六': {
              data.lastWeek[5] += 1
              break;
            }
            case '上周星期日': {
              data.lastWeek[6] += 1
              break;
            }
            default:
              break
          }
        }
      },

      /**
       * 查询设备
       */
      handleEquipment() {
        console.log('fffff')
        // getEquipment().then(res => {
        //   let data = res.result
        //   console.log(data)
        //   data.forEach((item, index) => {
        //     let {Week, isThisWeek} = isWeek(item.installDate);
        //     console.log(Week)
        //     this.setChartData(lineChartData.equipment,isThisWeek,Week)
        //   })
        // })
      },

      /**
       * 查询工程师
       */
      handleEngineer() {
        console.log('ddddd')
        // getEngineer().then(res => {
        //   let data = res.result
        //   console.log(data)
        //   // data.forEach((item, index) => {
        //   //   let {Week, isThisWeek} = isWeek(item.installDate);
        //   //   console.log(Week)
        //   //   this.setChartData(lineChartData.engineer,isThisWeek,Week)
        //   // })
        // })
      },

      /**
       * 查询维护教程
       */

      handleArticles() {
        console.log('wwwwww')
        // getProblem().then(res => {
        //   let data = res.result
        //   console.log(data)
        //   data.forEach((item, index) => {
        //     let {Week, isThisWeek} = isWeek(item.createTime);
        //     console.log(Week)
        //     this.setChartData(lineChartData.tutorialArticles,isThisWeek,Week)
        //   })
        // })
      },

      /**
       * 查看投诉建议
       */
      handleSuggestions() {
        console.log("ssss")
        // getEvaluate().then(res => {
        //   let data = res.result
        //   console.log(data)
        //   data.forEach((item, index) => {
        //     let {Week, isThisWeek} = isWeek(item.createTime);
        //     console.log(Week)
        //     this.setChartData(lineChartData.suggestions,isThisWeek,Week)
        //   })
        // })
      },
      /**
       * 查看工单
       */
      handleRepair() {
        console.log('aaaa')
        // findWorkList().then(res => {
        //   let data = res.result
        //   console.log(data)
        //   data.forEach((item, index) => {
        //     let {Week, isThisWeek} = isWeek(item.createTime);
        //     console.log(Week)
        //     this.setChartData(lineChartData.repair,isThisWeek,Week)
        //   })
        // })
      },
    }, mounted() {
      setTimeout(()=>{

      },3000)
      this.handleRepair()
      this.handleEquipment()
      // this.handleEngineer()
      this.handleArticles()
      this.handleSuggestions()
    }
  }
</script>

<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0px;
      border: 0;
      right: 0;
    }

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width: 1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
